package 排序;

import java.util.Arrays;
import java.util.Random;

public class Test {
    public static void initArrayOrder(int []array) {
        for (int i = 0; i < array.length; i++) {
            array[i]=i;
        }
        System.out.println("有序:");
    }
    public static void initArrayNotOrder(int []array) {
        Random random=new Random();
        for (int i = 0; i < array.length; i++) {
            array[i]=random.nextInt(1000_0000);
        }
        System.out.println("无序:");

    }
    public static void ReverseOrder(int []array) {
        for (int i = 0; i < array.length; i++) {
            array[i]= array.length-i;
        }
        System.out.println("逆序:");

    }
    //堆排序测试
    public static void testHeapSort(int []array) {
        int[]copy=Arrays.copyOf(array,array.length);
        Sort.createBigHeap(copy);
        long start = System.currentTimeMillis();
        Sort.HeapSort(copy);
        long end = System.currentTimeMillis();
        System.out.println("堆排序耗时"+(end-start));

    }
    //选择排序测试
    public static void testSelectSort(int []array) {
        int[]copy=Arrays.copyOf(array,array.length);
        long start = System.currentTimeMillis();
        Sort.selectSort(copy);
        long end = System.currentTimeMillis();
        System.out.println("选择耗时"+(end-start));

    }
    //希尔排序测试
    public static void testShellSort(int []array) {
        int[]copy=Arrays.copyOf(array,array.length);
        long start = System.currentTimeMillis();
        Sort.ShellSort(copy);
        long end = System.currentTimeMillis();
        System.out.println("希尔耗时"+(end-start));

    }
    private static void testInsertSort(int[]array) {
      int[]copy=Arrays.copyOf(array,array.length);
      long start = System.currentTimeMillis();
        Sort.InsertSort(copy);
      long end = System.currentTimeMillis();
         System.out.println("直接插入耗时"+(end-start));

    }
    private static void testQuickSort(int[]array) {
        int[]copy=Arrays.copyOf(array,array.length);
        long start = System.currentTimeMillis();
        Sort.quickSort(copy);
        long end = System.currentTimeMillis();
        System.out.println("快速耗时"+(end-start));

    }
    private static void testquickSortPlus(int[]array) {
        int[]copy=Arrays.copyOf(array,array.length);
        long start = System.currentTimeMillis();
        Sort.quickSortPlus(copy);
        long end = System.currentTimeMillis();
        System.out.println("快速耗时非递归"+(end-start));

    }
    private static void testMergeSort(int[]array) {
        int[]copy=Arrays.copyOf(array,array.length);
        long start = System.currentTimeMillis();
        Sort.mergeSort(copy);
        long end = System.currentTimeMillis();
        System.out.println("归并耗时"+(end-start));

    }
    private static void testMergeSortPlus(int[]array) {
        int[]copy=Arrays.copyOf(array,array.length);
        long start = System.currentTimeMillis();
        Sort.mergeSort(copy);
        long end = System.currentTimeMillis();
        System.out.println("归并非递归耗时"+(end-start));

    }
    public static void main(String[] args) {
        int[]array=new int[10_0000];
        //有序
        //initArrayOrder(array);
        //无序
        initArrayNotOrder(array);
        //逆序
        // ReverseOrder(array);
        //插入排序测试
        //testInsertSort(array);
        //希尔排序测试
        testShellSort(array);
        //选择排序测试
        //testSelectSort(array);
        //堆排序测试
        testHeapSort(array);
        //快速排序
        testQuickSort(array);
        //快排非递归
        testquickSortPlus(array);
        //归并
        testMergeSort(array);
        //归并非递归
        testMergeSortPlus(array);
        int[]ret={12,56,32,67,10,19,4};
        Sort.quickSort(ret);
        System.out.println(Arrays.toString(ret));
    }
    public static void main1(String[] args) {
        int[]array={12,56,32,67,10,19,4};
        Sort.quickSort(array);
        System.out.println(Arrays.toString(array));
    }
}
